import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-04-23
 * Time: 10:21
 */
public class Test {

    public static void orderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;//最有序
            array[i] = array.length - 1;//最无序
        }
    }

    public static void notOredeArray(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void testInsetSort(int[] arr){
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.insetSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序的时间: " + (endTime - startTime));
    }

    public static void testShellSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序的时间: " + (endTime - startTime));
    }

    public static void testSelectSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序的时间: " + (endTime - startTime));
    }

    public static void testSelectSort2(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort2(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序优化后的时间: " + (endTime - startTime));
    }

    public static void testHeapSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序的时间: " + (endTime - startTime));
    }

    public static void testBubbleSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序的时间: " + (endTime - startTime));
    }


    public static void testQuickSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序的时间: " + (endTime - startTime));
    }

    public static void testMregeSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序的时间: " + (endTime - startTime));
    }

    public static void testMregeSortNor(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSortNor(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序的非递归的时间: " + (endTime - startTime));
    }

    public static void testCountSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long startTime = System.currentTimeMillis();
        Sort.countSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("计数排序的时间: " + (endTime - startTime));
    }


    public static void testOther() {
        int[] arr = new int[10_0000];
        notOredeArray(arr);

        testInsetSort(arr);

        testShellSort(arr);

        //testSelectSort(arr);

        //testSelectSort2(arr);

        testHeapSort(arr);

        //testBubbleSort(arr);

        testQuickSort(arr);

        testMregeSort(arr);

        testMregeSortNor(arr);

        testCountSort(arr);
    }

    public static void simpleTest() {
        int[] array = {12 , 5 , 2 , 9 , 10 , 7};
        System.out.println("排序前: " + Arrays.toString(array));
        //Sort.insetSort(array);
        //Sort.shellSort(array);
        //Sort.selectSort(array);
        //Sort.selectSort2(array);
        //Sort.heapSort(array);
        //Sort.bubbleSort(array);
        //Sort.quickSort(array);
        //Sort.mergeSort(array);
        //Sort.mergeSortNor(array);
        Sort.countSort(array);
        System.out.println("排序后: " + Arrays.toString(array));
    }
    public static void main(String[] args) {
       simpleTest();
        testOther();
    }
}
